package cn.com.cym.gamezao.web.single;

import cn.com.cym.gamezao.annotation.AccessLimit;
import cn.com.cym.gamezao.annotation.AuthToken;
import cn.com.cym.gamezao.base.BaseController;
import cn.com.cym.gamezao.base.BaseService;
import cn.com.cym.gamezao.base.SearchPage;
import cn.com.cym.gamezao.dto.LostFoundDto;
import cn.com.cym.gamezao.entity.single.LostFound;
import cn.com.cym.gamezao.service.single.LostFoundService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
import org.springframework.web.bind.annotation.*;

@Api(tags = "s-失物招领")
@RestController
@RequestMapping(value = "lost")
@AuthToken(rule = "single.lostFound")
public class LostFoundController extends BaseController<LostFound> {

    final LostFoundService thisService;

    public LostFoundController(LostFoundService lostFoundService){
        this.thisService=lostFoundService;
    }

    @Override
    public BaseService<LostFound> getService() {
        return this.thisService;
    }

    @Override
    @AuthToken(require = false)
    @AccessLimit(limitCount = 15)
    public ResponseEntity<?> getById(@PathVariable @NonNull Long id) {
        return super.getById(id);
    }

    @Override
    @AuthToken(require = false)
    @AccessLimit(limitCount = 15)
    public ResponseEntity<?> page(@RequestBody SearchPage searchPage) {
        return super.page(searchPage);
    }


    @ApiImplicitParam(name = "lost", value = "lost", required = true,dataType = "LostFound")
    @ApiOperation(value = "新建")
    @ApiOperationSupport(order = 2, author = "mr.chen")
    @PostMapping("")
    @AuthToken(rule = "add")
    public ResponseEntity<?> add(@RequestBody LostFound lost){
        this.thisService.save(lost);
        return ResponseEntity.ok(lost);
    }

    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "id",paramType = "path", required = true,dataType = "Long"),
            @ApiImplicitParam(name = "lost", value = "lost",paramType = "", required = true,dataType = "LostFound")})
    @ApiOperation(value = "更新")
    @ApiOperationSupport(order = 3, author = "mr.chen")
    @PutMapping("/{id}")
    @AuthToken(rule = "update")
    public ResponseEntity<?> update(@RequestBody  LostFound lost,@PathVariable @NonNull Long id){
        final LostFound storeLost = this.thisService.update(lost,id);
        return ResponseEntity.ok(storeLost);
    }


    @ApiImplicitParam(name = "auditRequest", value = "auditRequest",required = true,dataType = "AuditRequest")
    @ApiOperation(value = "审核")
    @ApiOperationSupport(order = 5, author = "mr.chen")
    @PostMapping("/audit")
    @AuthToken(rule = "audit")
    public ResponseEntity<?> audit(@RequestBody LostFound lostFound){
        final LostFound audit = this.thisService.save(lostFound);
        return ResponseEntity.ok(audit);
    }


    @ApiImplicitParam(name = "lostFound", value = "lostFound",required = true,dataType = "LostFoundDto")
    @ApiOperation(value = "申请")
    @ApiOperationSupport(order = 2, author = "mr.chen")
    @PostMapping("/apply")
    @AuthToken(require = false)
    @AccessLimit(limitCount = 5)
    public ResponseEntity<?> apply(@RequestBody LostFoundDto lostFound){
        final LostFound apply = this.thisService.apply(lostFound);
        return ResponseEntity.ok(apply);
    }
}
